package com.outfood.service.impl;

import com.outfood.domain.Order;
import com.outfood.domain.Rule;
import com.outfood.service.IOrderService;
import com.outfood.service.IRuleService;
import com.rys.common.utils.StringUtils;
import com.rys.framework.service.base.BaseServcie;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @Author huisonglin
 * @Description
 * @PackageName outfood-platform
 * @Package com.outfood.service.impl
 * @Date 2024-03-25 17:05
 * @Version 1.0
 */
@Service
public class RuleServiceImpl extends BaseServcie<Rule> implements IRuleService {

    @Override
    public Integer getTime(Long ruleId, String orderPirce) {
        Integer excuteTime = getExcuteTime(ruleId, orderPirce);
        if(excuteTime == null){
            return this.get(ruleId).getTime();
        }else{
            return excuteTime;
        }
    }

    public Integer getExcuteTime(Long ruleId, String orderPirce){
        Rule rule = this.get(ruleId);

        if(StringUtils.isBlank(orderPirce)){
            return rule.getTime();
        }
        BigDecimal bigDecimal = new BigDecimal(orderPirce);
        if(bigDecimal.compareTo(new BigDecimal("50")) == -1){
            return rule.getTime();
        }
        if(bigDecimal.compareTo(new BigDecimal("100")) ==  -1){
            return rule.getMidOrderTime();
        }else{
            return rule.getMaxOrderTime();
        }

    }

}
